function flatten(arr){
    while(arr.some(item=>Array.isArray(item))){
        console.log(arr);
        arr = [].concat(...arr);
        
    }
    return arr;
}
console.log(flatten([[1,2],[3,4,[5,6,7,[8,9]]]]));